package logic

import (
	"context"

	"backend/apps/book/api/internal/svc"
	"backend/apps/book/api/internal/types"
	"backend/apps/book/proto"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateAuthorLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateAuthorLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateAuthorLogic {
	return &CreateAuthorLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateAuthorLogic) CreateAuthor(req *types.Author) (resp *types.CommonResponse, err error) {
	_, err = l.svcCtx.BookRpc.CreateAuthor(l.ctx, &proto.Author{
		Name:         req.Name,
		Introduction: req.Introduction,
		AvatarUrl:    req.Avatar_url,
	})
	return resp, err
}
